var util = require('../../../../utils/util.js');
var api = require('../../../../config/api.js');
var app = getApp();

Page({
  data: {
    taskId: '',
    taskState: '',
    pendingTask: [],
    tmCrReqEntity: {}
  },
  getData: function () {
    let that = this;
    that.getPendingTask();
  },
  getPendingTask() {
    var that = this;
    util.request(api.PendingTaskDetail, {taskId: that.data.taskId })
      .then(function (res) {
        if (res.code === 0) {
          that.setData({
            pendingTask: res.tmPendingTask,
            tmCrReqEntity: res.tmCrReqEntity
          });
        }
      });
  },
  goApprove: function (e) {
    var vTaskId = e.target.dataset.taskId;
    var vTaskState = e.target.dataset.taskState;
    wx.showToast({
      title: '操作中...',
      icon: 'loading',
      duration: 5000
    })
    util.request(api.PendingTaskApprove, {taskId: vTaskId , taskState: vTaskState })
      .then(function (res) {
        if (res.code === 0) {
          wx.showModal({
              title: '提示',
              content: '操作成功',
              showCancel: false
          })
          wx.redirectTo({
              url: '/pages/cr/businessHand/pendingTaskList/pendingTaskList'
          });
        } else {
            wx.showModal({
                title: '提示',
                content: '操作失败',
                showCancel: false
            })
        }
      });
  },
  
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    var that = this
    that.setData({
      taskId: options.taskId
    })
    that.getData();
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示

  },
  onHide: function () {
    // 页面隐藏

  },
  onUnload: function () {
    // 页面关闭

  }
})